<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>部门管理</title>
</head>
<body class="hold-transition skin-black sidebar-mini">
    <div th:replace="common/fragment :: link"></div>
    <div class="wrapper">
        <div th:replace="common/fragment :: navbar"></div>
        <div th:replace="common/fragment :: menu"></div>
        <div class="content-wrapper">
            <section class="content-header">
                <h1>部门管理</h1>
            </section>
            <section class="content">
                <div class="box">
                    <!--高级查询--->
                    <form class="form-inline" id="searchForm" action="/department/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                        <script>
                            $(function () {
                                $(".btn-input").click(function () {
                                    let json = $(this).data("json");
                                    console.log(json);
                                    $(".form-horizontal :input").val('');
                                    if (json) {
                                        console.log($(".form-horizontal :input"));
                                        $(".form-horizontal :input[name=id]").val(json.id);
                                        $(".form-horizontal :input[name=name]").val(json.name);
                                        $(".form-horizontal :input[name=sn]").val(json.sn);
                                    }

                                    $("#modelFade").modal('show')
                                })


                            })
                        </script>
                    </form>
                    <!--编写内容-->
                    <div class="box-body table-responsive ">
                        <table class="table table-hover table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>部门名称</th>
                                <th>部门编号</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                                <tr th:each="d:${pageInfo.list}">
                                    <td th:text="${d.id}">1</td>
                                    <td th:text="${d.name}">开发部</td>
                                    <td th:text="${d.sn}">DEV</td>
                                    <td>
                                        <a href="#" class="btn btn-info btn-xs btn-input" th:data-json='${d.json}'>
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                        <a class="btn btn-danger btn-xs btn-delete" th:data-url="|/department/delete?id=${d.id}|">
                                            <span class="glyphicon glyphicon-trash"></span> 删除
                                        </a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
<!--                        <div th:replace="common/fragment :: page"></div>-->
                        <ul id="pagination" class="pagination"></ul>
                        <script th:inline="javascript">
                            //分页
                            $(function(){
                                // var totalPages = /*[[${pageInfo.pages}]]*/ 1;
                                // var startPage = /*[[${pageInfo.pageNum}]]*/ 1;
                                $('#pagination').twbsPagination({
                                    totalPages: /*[[${pageInfo.pages}]]*/ 1,
                                    startPage:/*[[${pageInfo.pageNum}]]*/ 1,
                                    first:'首页',
                                    prev:'上一页',
                                    next:'下一页',
                                    last:'尾页',
                                    visiblePages: 5,
                                    onPageClick: function (event, page) {
                                        $('#currentPage').val(page);
                                        $('#searchForm').submit();
                                    }
                                });
                            })
                        </script>
                    </div>
                </div>
            </section>
        </div>
        <div th:replace="common/fragment :: footer"></div>
    </div>

    <div class="modal fade" id="modelFade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">部门新增或修改</h4>
                </div>
                <form action="/department/saveOrUpdate" method="post" id="formSave" class="form-horizontal">
                    <input type="hidden" name="id">
                    <div class="modal-body">
                        <div class="form-group">
                                <label for="dSn" class="col-sm-2 control-label">部门编号</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="sn" id="dSn" placeholder="请输入部门编号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="dName" class="col-sm-2 control-label">部门名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="dName" placeholder="请输入部门名称">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </div>

                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>

    <div class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">部门编辑</h4>
                </div>
                <form action="/department/saveOrUpdate" method="post">
                    <input type="hidden" name="id">
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="name">名称</label>
                            <input type="text" class="form-control" name="name" id="name" placeholder="名称">
                        </div>
                        <div class="form-group">
                            <label for="sn">缩写</label>
                            <input type="text" class="form-control" name="sn" id="sn" placeholder="缩写">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>